<?php


use Yaf\Registry;
use models\Business\Announce;
use models\Exception\Business\AnnouncestatsException;

class AnnounceController extends ApiBaseController
{
    /**
     * @SWG\Get(
     *     path="/v3/announce/list",
     *     tags={"系统消息"},
     *     summary="获取系统消息列表数据接口",
     *     description="
     * app_id 必须参数 app_id
     * page 必须参数 页码
     * page_size 必须参数 每页显示条数
     * sort 必须参数 排序方式 固定值:desc
     * order 必须参数 排序字段 固定值:id",
     *     @SWG\Parameter(
     *          name="Authorization",
     *          description="Authorization 登录接口返回的jwt字段的值",
     *          in="header",
     *          required=true,
     *          type="string"
     *     ),
     *     @SWG\Parameter(
     *          name="secret",
     *          description="加密字符串",
     *          in="query",
     *          required=true,
     *          type="string"
     *     ),
     *     @SWG\Response(
     *         response="200",
     *         description="请求成功",
     *         @SWG\Schema(type="object", ref="#/definitions/announceListData")
     *     ),
     *     @SWG\Response(
     *         response="400",
     *         description="签名不存在或无效签名"
     *     ),
     *     @SWG\Response(
     *         response="401",
     *         description="jwt无效或过期，需要登录"
     *     ),
     *     @SWG\Response(
     *         response="403",
     *         description="无权访问"
     *     ),
     *     @SWG\Response(
     *         response="404",
     *         description="找不到数据"
     *     )
     * )
     */
    public function listAction() {
        $parameters = Registry::get('parameters');
        $parameters['stats'] = 1;

        $announce = Announce::getAnnounceList($parameters);

        return $this->_responseJson($announce);
    }

    /**
     * @SWG\Put(
     *     path="/v3/announce/{id}/edit",
     *     tags={"系统消息"},
     *     summary="已读某条消息",
     *     description="
     * app_id 必须参数 app_id",
     *     @SWG\Parameter(
     *          name="Authorization",
     *          description="Authorization 登录接口返回的jwt字段的值",
     *          in="header",
     *          required=true,
     *          type="string"
     *     ),
     *     @SWG\Parameter(
     *          name="id",
     *          description="/admin/Announce/list接口返回的id字段的值",
     *          in="path",
     *          required=true,
     *          type="string"
     *     ),
     *     @SWG\Parameter(
     *          name="secret",
     *          description="加密字符串",
     *          in="formData",
     *          required=false,
     *          type="string"
     *     ),
     *     @SWG\Response(
     *         response="200",
     *         description="请求成功",
     *         @SWG\Schema(type="object", ref="#/definitions/announceSingleData")
     *     ),
     *     @SWG\Response(
     *         response="422",
     *         description="编辑失败"
     *     ),
     *     @SWG\Response(
     *         response="400",
     *         description="签名不存在或无效签名"
     *     ),
     *     @SWG\Response(
     *         response="401",
     *         description="jwt无效或过期，需要登录"
     *     ),
     *     @SWG\Response(
     *         response="403",
     *         description="无权访问"
     *     ),
     *     @SWG\Response(
     *         response="404",
     *         description="找不到数据"
     *     )
     * )
     */
    public function readAction() {
        $parameters = Registry::get('parameters');

        Announce::readAnnounce($parameters);

        return $this->_responseJson(new stdClass(), '000', AnnouncestatsException::ANNOUNCE_READ_SUCCESS);
    }

}
